package com.airticketbooking.controller.manager;

import com.airticketbooking.common.domain.PageDTO;
import com.airticketbooking.common.domain.Result;
import com.airticketbooking.dto.TicketDTO;
import com.airticketbooking.query.TicketPageQuery;
import com.airticketbooking.vo.TicketVO;
import com.airticketbooking.service.TicketService;
import com.github.pagehelper.Page;
import io.swagger.annotations.Api;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;




@RestController
@RequiredArgsConstructor
@Api(tags = "票据管理")
@RequestMapping("/air/manager/Ticket")
public class MTicketController {

	private final TicketService ticketService;


	@GetMapping("/page")
	public Result<PageDTO<TicketVO>> pageQuerylist(TicketPageQuery ticketPageQuery) {


		Page<TicketVO> ticketVOList = ticketService.pageQuerylist(ticketPageQuery);
		PageDTO<TicketVO> pageDTO = new PageDTO<>();
		pageDTO.setList(ticketVOList.getResult());
		pageDTO.setTotal(ticketVOList.getTotal());

		return Result.ok(pageDTO);
	}


	@GetMapping("/add")
	public Result<String> addTickets(Integer scheduleId) {

		try {
			ticketService.addTickets(scheduleId);
			return Result.ok("Add ticket successfully");
		} catch (Exception e) {
			return Result.error(e.getMessage());
		}
	}

	@PutMapping("/update")
	public Result<String> update(@RequestBody TicketDTO ticketDTO) {
		ticketService.update(ticketDTO);
		return Result.ok("Update ticket successfully");
	}

	//	根据id查找票据
	@GetMapping("/getTicketById/{id}")
	public Result<TicketVO> getTicketById(@PathVariable Integer id) {
		TicketVO ticketVO = ticketService.getTicketById(id);
		return Result.ok(ticketVO);
	}

	//	startOrstopTicket
	@GetMapping("/startOrstop")
	public Result<Integer> startOrstopTicket(Integer scheduleId) {
		try {
			Integer status = ticketService.startOrstopTicket(scheduleId);

			return Result.ok(status);

		} catch (Exception e) {
			return Result.error(e.getMessage());
		}

	}


}
